﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.Core.Support;
using MS.InformationManagement.DAL.DocumentCenter;
using Microsoft.SharePoint;

namespace MS.InformationManagement.BLL.DocumentPrinter
{
    public class UpdateDeliveryStatusCommand : IBaseCommand
    {

        #region Fields

        IEnumerable<EnvíoDeCorrespondencia> _documentsSent;

        #endregion

        #region Constructors

        public UpdateDeliveryStatusCommand(IEnumerable<EnvíoDeCorrespondencia> documentsSent)
        {
            _documentsSent = documentsSent;
        }

        #endregion

        #region Command Implementation

        public void Execute()
        {
            using (var dc = new DCDocumentCenterDataContext(SPContext.Current.Web.Url))
            {

                foreach (var currentDocument in _documentsSent)
                {
                    currentDocument.Enviado = true;
                    dc.EnviosDeCorreo.Attach(currentDocument);
                }

                dc.SubmitChanges();
            }
        }

        public void Undo()
        {
            using (var dc = new DCDocumentCenterDataContext(SPContext.Current.Web.Url))
            {

                foreach (var currentDocument in _documentsSent)
                {
                    currentDocument.Enviado = false;
                    dc.EnviosDeCorreo.Attach(currentDocument);
                }

                dc.SubmitChanges();
            }
        }

        #endregion
    }
}
